package com.norbitltd.guavaleaves.java.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;

import com.google.common.base.Function;

public class DateFunctions {
	
	public static Function<Date, String> toString(final SimpleDateFormat format) {
		return new Function<Date, String>() {
			public String apply(Date input) {
				return format == null ? null : format.format(input);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addDays
	 */
	public static Function<Date, Date> addDays(final int days) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addDays(input, days);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addHours
	 */
	public static Function<Date, Date> addHours(final int hours) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addHours(input, hours);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addMilliseconds
	 */
	public static Function<Date, Date> addMilliseconds(final int milliseconds) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addMilliseconds(input, milliseconds);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addMinutes
	 */
	public static Function<Date, Date> addMinutes(final int minutes) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addMinutes(input, minutes);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addMonths
	 */
	public static Function<Date, Date> addMonths(final int months) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addMonths(input, months);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addSeconds
	 */
	public static Function<Date, Date> addSeconds(final int seconds) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addSeconds(input, seconds);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addWeeks
	 */
	public static Function<Date, Date> addWeeks(final int weeks) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addWeeks(input, weeks);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.addYears
	 */
	public static Function<Date, Date> addYears(final int years) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.addYears(input, years);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.ceiling
	 */
	public Function<Date, Date> ceiling(final int field) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.ceiling(input, field);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.round
	 */
	public Function<Date, Date> round(final int field) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.round(input, field);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.truncate
	 */
	public Function<Date, Date> truncate(final int field) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.truncate(input, field);
			}
		};
	}
	

	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setDays
	 */
	public static Function<Date, Date> setDays(final int days) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setDays(input, days);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setHours
	 */
	public static Function<Date, Date> setHours(final int hours) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setHours(input, hours);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setMilliseconds
	 */
	public static Function<Date, Date> setMilliseconds(final int milliseconds) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setMilliseconds(input, milliseconds);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setMinutes
	 */
	public static Function<Date, Date> setMinutes(final int minutes) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setMinutes(input, minutes);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setMonths
	 */
	public static Function<Date, Date> setMonths(final int months) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setMonths(input, months);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setSeconds
	 */
	public static Function<Date, Date> setSeconds(final int seconds) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setSeconds(input, seconds);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.DateUtils.setYears
	 */
	public static Function<Date, Date> setYears(final int years) {
		return new Function<Date, Date>() {
			public Date apply(Date input) {
				return DateUtils.setYears(input, years);
			}
		};
	}
	
	
}
